#pragma once
#include "RBTree.h"

namespace lzc {
	template <class K, class V, class Comp = std::less<K>>
	class map {
		typedef std::pair<const K, V> T;
		struct mapKeyOfT {
			const K& operator()(const T& data)
			{
				return data.first;
			}
		};
	public:
		typedef RBTree<K, T, mapKeyOfT, Comp> Rep_type;
		typedef typename Rep_type::iterator iterator;
		typedef typename Rep_type::const_iterator const_iterator;

		iterator begin()
		{
			return rb_tree.begin();
		}
		iterator end()
		{
			return rb_tree.end();
		}
		
		std::pair<iterator, bool> insert(const T& x)
		{
			return rb_tree.insert(x);
		}
		bool erase(const K& key)
		{
			return rb_tree.erase(key);
		}
		V& operator[](const K& key)
		{
			std::pair<iterator, bool> ret = insert(T(key, V()));
			return ret.first->second;
		}
	private:
		Rep_type rb_tree;
	};
}